Skip to content

fix(server): the Claude usage calendar keeps days after Claude deletes its files - #1053

Merged
badcuban merged 1 commit into
mainfrom
fix/claude-usage-calendar-history
Nov 23, 2026
Merged

badcuban merged 1 commit into
mainfrom
fix/claude-usage-calendar-history

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

The Claude "Local token activity" calendar in Settings > Providers > Usage only reached back about a month. It's built from Claude Code's transcript files, and Claude Code deletes those cleanupPeriodDays (30 by default) after they were last written. Threadlines meant to keep its own rolling year in the provider status cache, but every restart wiped it: the pending snapshot (sign-in unknown, no token history) replaced the saved one, and dev servers share that cache folder.

Each read now folds its daily totals into a saved history file under the server's state folder (provider-token-history/claude-<hash>.json, one per Claude folder). A day keeps the larger of what was saved and what was read, so a deleted transcript can't lower or erase it. All readers of one file share a lock and re-read the file before saving, so two instances of one folder can't overwrite each other from stale copies. A file this build can't read is left alone, and a failed save is retried on the next read.

The reader also:

  • takes the larger of Claude's stats cache and the scan for each day, instead of letting the scan replace the cache's days
  • keeps saved days when the transcript scan is incomplete
  • computes the lifetime total as Claude's own total plus what saved days add on top, so it never drops when a transcript is deleted
  • extends the coverage end date to the last saved day

Codex isn't affected: its calendar comes from OpenAI's servers.

Days deleted before this ships can't be recovered. The calendar fills toward a full year from here.

Tested with a new case in ProviderRegistry.test.ts: two readers of one folder, a transcript deleted between them, and the saved file checked afterwards. It fails without the store. Format, lint and typecheck pass, and the related server test files pass (160 tests).

…s its files

The Local token activity calendar for Claude only reached back about a
month. It is built from Claude Code's transcript files, which Claude Code
deletes cleanupPeriodDays (30 by default) after they were last written.
Threadlines meant to keep its own rolling year in the provider status
cache, but a restart's pending snapshot (sign-in unknown, no history)
replaced it, and dev servers share that cache folder.

Each read now folds its daily totals into a saved history file in the
server's state folder (one per Claude folder). A day keeps the larger of
what was saved and what was read, so a deleted transcript no longer lowers
or erases it. Every reader of one file shares a lock and re-reads the file
before saving, so two instances of one folder can't overwrite each other.
A file this build can't read is left alone.

The reader also takes the larger of Claude's stats cache and the scan for
each day instead of replacing the cache's days, keeps saved days when the
scan is incomplete, and computes the lifetime total so it never drops when
a transcript is deleted.
@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 23, 2026 3:59pm UTC

Request Review

@badcuban
badcuban added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 02cacea Nov 23, 2026
23 checks passed
@badcuban
badcuban deleted the fix/claude-usage-calendar-history branch November 23, 2026 16:11

This branch was previously deployed

1 inactive deployment
Preview — fc687dbf Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant